#ifndef __DEBUGLOG_H__
#define __DEBUGLOG_H__

#include <fstream>
#include <d3d9.h>

#ifdef _DEBUG

class TraceFunction
{
public:
	TraceFunction( TCHAR* funcName );
	~TraceFunction( );
private:
	TCHAR*	_funcName;
};

#define TRACEFUNC TraceFunction traceFunction( TEXT( __FUNCTION__ ) );

class DebugLog
{
public:
	static DebugLog* _( );
	~DebugLog( );
	std::wofstream debugLog;
	unsigned long countMessages;
	bool CheckForDxError( TCHAR* file, int line, HRESULT hr );
	void trace( std::wstring string );
	void trace( int num );
		
private:
	DebugLog( );
	static DebugLog* __;
};

#define CheckHr(hr) DebugLog::_()->CheckForDxError( __FILE__, __LINE__, hr )

#define DEBUGSPACE DebugLog::_()->debugLog << ( "\t" );
#define DEBUGENDL DebugLog::_()->debugLog << std::endl;

#define DEBUGLOGINFO(message) DebugLog::_()->debugLog << __DATE__ << " " << __TIME__ << " " << __FILE__ << " (" << __LINE__ << ") " << __FUNCTION__ << "\t";
#define DEBUGLOG(message) DebugLog::_()->debugLog << (message);
#define DEBUGLOGLN(message) DEBUGLOG(message) DEBUGENDL
#define DEBUGPARAM(name, value) DebugLog::_()->debugLog << "    " << (name) << " = " << (value);
#define DEBUGTRACE(message) DebugLog::_()->trace(message);

#else

#define DEBUGSPACE
#define DEBUGENDL
#define DEBUGLOGINFO(message)
#define DEBUGTRACE(message)
#define DEBUGLOG(message)
#define DEBUGPARAM(name, value)
#define DEBUGLOGLN(message)
#define CheckHr(hr) (hr)
#define TRACEFUNC

#endif

#endif
